xenstore: Small cleanups and fixes.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 24 Jul 2007 17:28:48 +0000 (18:28 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 24 Jul 2007 17:28:48 +0000 (18:28 +0100)
 1. readfd/writefd account for EINTR/EAGAIN errno returns.
 2. Handle zero return from ->read() and ->write() handlers
    symmetrically.
 3. Fix some indentation issues (use hard tabs).
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/xenstore/xenstored_core.c
tools/xenstore/xenstored_domain.c
tools/xenstore/xenstored_watch.c

index f62de82b77d35f4003cf2cc632e8a505ec38bac8..1081103459e6495fe9662acaeb9db5c3b88a192a 100644 (file)
@@ -1266,7 +1266,7 @@ static void handle_input(struct connection *conn)
        if (in->inhdr) {
                bytes = conn->read(conn, in->hdr.raw + in->used,
                                   sizeof(in->hdr) - in->used);
-               if (bytes <= 0)
+               if (bytes < 0)
                        goto bad_client;
                in->used += bytes;
                if (in->used != sizeof(in->hdr))
@@ -1288,7 +1288,7 @@ static void handle_input(struct connection *conn)
 
        bytes = conn->read(conn, in->buffer + in->used,
                           in->hdr.msg.len - in->used);
-       if (bytes <= 0)
+       if (bytes < 0)
                goto bad_client;
 
        in->used += bytes;
@@ -1341,12 +1341,34 @@ struct connection *new_connection(connwritefn_t *write, connreadfn_t *read)
 
 static int writefd(struct connection *conn, const void *data, unsigned int len)
 {
-       return write(conn->fd, data, len);
+       int rc;
+
+       while ((rc = write(conn->fd, data, len)) < 0) {
+               if (errno == EAGAIN) {
+                       rc = 0;
+                       break;
+               }
+               if (errno != EINTR)
+                       break;
+       }
+
+       return rc;
 }
 
 static int readfd(struct connection *conn, void *data, unsigned int len)
 {
-       return read(conn->fd, data, len);
+       int rc;
+
+       while ((rc = read(conn->fd, data, len)) < 0) {
+               if (errno == EAGAIN) {
+                       rc = 0;
+                       break;
+               }
+               if (errno != EINTR)
+                       break;
+       }
+
+       return rc;
 }
 
 static void accept_connection(int sock, bool canwrite)
@@ -1439,13 +1461,13 @@ static void setup_structure(void)
 static unsigned int hash_from_key_fn(void *k)
 {
        char *str = k;
-        unsigned int hash = 5381;
-        char c;
+       unsigned int hash = 5381;
+       char c;
 
-        while ((c = *str++))
+       while ((c = *str++))
                hash = ((hash << 5) + hash) + (unsigned int)c;
 
-        return hash;
+       return hash;
 }
 
 
index c51e2c73b9a4c019b43da7f2c6ab08197a61d140..d166c0556e1014dbd2379b23fbce728c17f2501a 100644 (file)
@@ -76,7 +76,6 @@ struct domain
 
 static LIST_HEAD(domains);
 
-/* FIXME: Mark connection as broken (close it?) when this happens. */
 static bool check_indexes(XENSTORE_RING_IDX cons, XENSTORE_RING_IDX prod)
 {
        return ((prod - cons) <= XENSTORE_RING_SIZE);
@@ -102,7 +101,8 @@ static const void *get_input_chunk(XENSTORE_RING_IDX cons,
        return buf + MASK_XENSTORE_IDX(cons);
 }
 
-static int writechn(struct connection *conn, const void *data, unsigned int len)
+static int writechn(struct connection *conn,
+                   const void *data, unsigned int len)
 {
        uint32_t avail;
        void *dest;
@@ -113,6 +113,7 @@ static int writechn(struct connection *conn, const void *data, unsigned int len)
        cons = intf->rsp_cons;
        prod = intf->rsp_prod;
        mb();
+
        if (!check_indexes(cons, prod)) {
                errno = EIO;
                return -1;
index 27e082a24fa46067c331f9f4856e0d868c16cc28..f5692f83e5763572559e4b5fdac50d3d450b51ad 100644 (file)
@@ -73,11 +73,10 @@ static void add_event(struct connection *conn,
        data = talloc_array(watch, char, len);
        strcpy(data, name);
        strcpy(data + strlen(name) + 1, watch->token);
-        send_reply(conn, XS_WATCH_EVENT, data, len);
+       send_reply(conn, XS_WATCH_EVENT, data, len);
        talloc_free(data);
 }
 
-/* FIXME: we fail to fire on out of memory.  Should drop connections. */
 void fire_watches(struct connection *conn, const char *name, bool recurse)
 {
        struct connection *i;
@@ -130,7 +129,7 @@ void do_watch(struct connection *conn, struct buffered_data *in)
        /* Check for duplicates. */
        list_for_each_entry(watch, &conn->watches, list) {
                if (streq(watch->node, vec[0]) &&
-                    streq(watch->token, vec[1])) {
+                   streq(watch->token, vec[1])) {
                        send_error(conn, EEXIST);
                        return;
                }